package cn.gene.timeyan.search.webapi.controller;

import cn.gene.timeyan.common.restful.JsonPage;
import cn.gene.timeyan.common.restful.JsonResult;
import cn.gene.timeyan.pojo.search.entity.ShareForElastic;
import cn.gene.timeyan.pojo.search.entity.ShareForElasticAll;
import cn.gene.timeyan.search.service.IShareForService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 分享*
 *
 * @author LWG
 * @date 2022/7/25 11:14
 * @since 1.0.0@gene.cn
 */
@RestController
@RequestMapping("/search1")
@Api(tags = "搜索分享模块")
public class ShareController {
    @Autowired(required = false)
    private IShareForService shareForService;

    // 搜索模块最主要的功能就是实现搜索
    // 面对这种功能对应的控制器方法,可以不写任何路径
    // 按下面@GetMapping注解表示当前控制路径为localhost:10008/search
    @GetMapping("/share")
    @ApiOperation("根据关键字查询ES中的信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "搜索关键字",name = "keyword",dataType = "string",
                    required = true),
            @ApiImplicitParam(value = "页码",name = "page",dataType = "int",
                    required = true),
            @ApiImplicitParam(value = "每页条数",name = "pageSize",dataType = "int",
                    required = true)
    })
    public JsonResult<List<ShareForElasticAll>> searchByKeyword(
            String keyword,
            @RequestParam(value = "page",defaultValue = "1")Integer page,
            @RequestParam(value = "pageSize",defaultValue = "2") Integer pageSize
    ){
        List<ShareForElasticAll> list=shareForService.search(keyword,page,pageSize);
        return JsonResult.ok(list);
    }
    @GetMapping("/keyWord")
    @ApiOperation("获取关键字")
    @ApiImplicitParam(value = "搜索关键字",name = "keyword",dataType = "string",
            required = true)
    public JsonResult<String> getKeyword(
            String keyword
    ){
        String keyWord=shareForService.getKeyWord(keyword);
        return JsonResult.ok(keyWord);
    }
}


